﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="FailOtsing", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(FailOtsing))]
    public class FailOtsingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IFailOtsing clazz;
        
        public FailOtsingSerializer(IFailOtsing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.AlgusKP!=null) {
                Writer.WriteStartElement("AlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Alustaja!=null) {
                Writer.WriteStartElement("Alustaja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Alustaja))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Nimetus!=null) {
                Writer.WriteStartElement("Nimetus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimetus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ObjektID!=null) {
                Writer.WriteStartElement("ObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Maht!=null) {
                Writer.WriteStartElement("Maht");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.Maht))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Laiend!=null) {
                Writer.WriteStartElement("Laiend");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Laiend))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="AlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Alustaja") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Alustaja = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Alustaja")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Nimetus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Nimetus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ObjektID") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.ObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ObjektID")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Maht") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>FailOtsing>Maht");
                }
                clazz.Maht = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("Maht")).Value;
            }
            if (Reader.LocalName=="Laiend") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Laiend = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Laiend")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
